unit testuibconnection;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  fpcunit,
  //testutils,
  testregistry,
  hadeuibconnection;

type

  { TTestUIBConnection }

  TTestUIBConnection= class(TTestCase)
  private
    fConnection:THadeUIBConnection;
  protected
    procedure SetUp; override; 
    procedure TearDown; override;
    procedure doConnect;
  published
    procedure TestConnect;
    procedure TestDisconnect;
    Procedure TestsetDataSet;
    procedure TestStartTransaction;
    procedure TestCommit;
    procedure TestRollback;
  end; 

implementation
uses
  hadeexception,
  uib;

procedure TTestUIBConnection.SetUp; 
begin
  fConnection:=THadeUIBConnection.Create;
end; 

procedure TTestUIBConnection.TearDown; 
begin
  FreeAndNil(fConnection);
end;

procedure TTestUIBConnection.doConnect;
begin
  FConnection.Database:='test';
  FConnection.Username:='SYSDBA';
  FCOnnection.Password:='masterkey';

  FConnection.Connect;
end;

procedure TTestUIBConnection.TestConnect;
begin
  Try
    doConnect;
    AssertEquals(TRUE,FConnection.IsConnected);
  except
  on E:EHadeDatabase do
    Fail('Failed! it Should Connect.'+E.Message);
  end;
end;

procedure TTestUIBConnection.TestDisconnect;
begin
  Try
    FConnection.Disconnect;
    AssertEquals(FALSE,FConnection.IsConnected);
  except
  on E:EHadeDatabase do
    Fail('Failed!'+E.Message);
  end;
end;

procedure TTestUIBConnection.TestsetDataSet;
var
  fquery: TUIBQuery;
begin
  fquery:=TUibquery.Create(nil);
  Try
    try
      FConnection.setDataSet(fQuery);
    except
    on E:Exception do
      Fail('Failed!'+E.Message);
    end;
  finally
    FreeAndNil(fQuery);
  end;
end;

procedure TTestUIBConnection.TestStartTransaction;
begin
  doConnect;
  Try
    FConnection.StartTransaction;
  except
  on E:EHadeDatabase do
    Fail('Failed!'+E.Message);
  end;
end;

procedure TTestUIBConnection.TestCommit;
begin
  Try
    FConnection.Commit;
  except
  on E:EHadeDatabase do
    Fail('Failed!'+E.Message);
  end;
end;

procedure TTestUIBConnection.TestRollback;
begin
  Try
    FConnection.Rollback;
  except
  on E:EHadeDatabase do
    Fail('Failed!'+E.Message);
  end;
end;

initialization

  RegisterTest(TTestUIBConnection); 
end.

